package com.umfwechat.util.wx;

import net.sf.json.JSONException;
import net.sf.json.JSONObject;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.umfwechat.wx.pojo.AccessTokenOAuth;
import com.umfwechat.wx.pojo.AccessTokenPojo;
import com.umfwechat.wx.pojo.CustomMenu;
import com.umfwechat.wx.pojo.Menu;
import com.umfwechat.wx.pojo.TicketPojo;

/**
 * 公众平台通用接口工具类
 */
public class WeixinUtil {

	private static Logger log = LoggerFactory.getLogger(WeixinUtil.class);
	
	/**
	 * 获取access_token
	 * 
	 * @param appid
	 *            凭证
	 * @param appsecret
	 *            密钥
	 * @return
	 */
	public static AccessTokenPojo getAccessToken(String appid, String appsecret) {
		// 获取access_token的接口地址（GET） 限200（次/天）
		String access_token_url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET";
		AccessTokenPojo accessToken = null;
		String requestUrl = access_token_url.replace("APPID", appid).replace("APPSECRET", appsecret);
		JSONObject jsonObject = WeixinHttpClientUtils.httpRequest(requestUrl, "GET", null);
		// 如果请求成功
		log.info("jsonObject!!!!!!!!!!!获取access_token!!!!!!!++++++++"+jsonObject);
		if (null != jsonObject) {
			try {
				accessToken = new AccessTokenPojo();
				accessToken.setAccessToken(jsonObject.getString("access_token"));
				accessToken.setExpiresIn(jsonObject.getInt("expires_in"));
			} catch (JSONException e) {
				accessToken = null;
				// 获取token失败
				log.error("获取accessToken失败 errcode:{} errmsg:{}", jsonObject.getInt("errcode"),
						jsonObject.getString("errmsg"));
			}
		}
		return accessToken;
	}

	/**
	 * 获取网页授权access_token
	 * @return
	 */
	public static AccessTokenOAuth getAccessTokenOAuth(String appid, String appsecret,String code) {
		AccessTokenOAuth accessTokenOAuth = null;
		String access_token_url ="https://api.weixin.qq.com/sns/oauth2/access_token?appid=APPID&secret=SECRET&code=CODE&grant_type=authorization_code";
		String requestUrl =access_token_url.replace("APPID",appid).replace("SECRET",appsecret).replace("CODE", code);
		JSONObject jsonObject = WeixinHttpClientUtils.httpRequest(requestUrl, "GET", null);
		log.info("jsonObject!!!!!!获取网页授权access_token!!!!!!!!!!!!++++++++"+jsonObject);
		// 如果请求成功
		if (null != jsonObject) {
			try {
				accessTokenOAuth = new AccessTokenOAuth();
				accessTokenOAuth.setAccess_token(jsonObject.getString("access_token"));
				accessTokenOAuth.setExpires_in(jsonObject.getInt("expires_in"));
				accessTokenOAuth.setOpenid(jsonObject.getString("openid"));
				accessTokenOAuth.setRefresh_token(jsonObject.getString("refresh_token"));
				accessTokenOAuth.setScope(jsonObject.getString("scope"));
				log.error("获取accessToken成功   AccessTokenOAuth：{}",accessTokenOAuth);
			} catch (JSONException e) {
				accessTokenOAuth = null;
				// 获取token失败
				log.error("获取accessToken失败 errcode:{} errmsg:{}", jsonObject.getInt("errcode"),
						jsonObject.getString("errmsg"));
			}
		}
		return accessTokenOAuth;
	}

	
	/**
	 * 获取微信JSSDK的ticket 
	 * @return
	 */
	public static String getJSSDKTicket(String token) {
		// 获取ticket的接口地址（GET） 限200（次/天）
		String access_token_url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=ACCESS_TOKEN&type=jsapi";
		String jssdkTicket = null;
		String requestUrl = access_token_url.replace("ACCESS_TOKEN",token);
		JSONObject jsonObject = WeixinHttpClientUtils.httpRequest(requestUrl, "GET", null);
		log.info("jsonObject!!!!!!获取微信JSSDK的ticket !!!!!!!!!!!!++++++++"+jsonObject);
		// 如果请求成功
		if (null != jsonObject) {
			try {
				jssdkTicket=jsonObject.getString("ticket");
				log.info("获取ticket成功  ticket:{}",jssdkTicket);
			} catch (JSONException e) {
				jssdkTicket=null;
				// 获取token失败
				log.error("获取ticket失败 errcode:{} errmsg:{}", jsonObject.getInt("errcode"),
						jsonObject.getString("errmsg"));
			}
		}
		return jssdkTicket;
	}

	/**
	 * 获取自定义菜单配置接口
	 * 
	 * @param menu
	 *            菜单实例
	 * @param accessToken
	 *            有效的access_token
	 * @return 0表示成功，其他值表示失败
	 */
	public static JSONObject getCustomMenu(String accessToken) {
		String menu_create_url = "https://api.weixin.qq.com/cgi-bin/get_current_selfmenu_info?access_token=ACCESS_TOKEN";
		// 拼装创建菜单的url
		String requestUrl = menu_create_url.replace("ACCESS_TOKEN", accessToken);
		// 将菜单对象转换成json字符串
		// String jsonMenu = JSONObject.fromObject(menu).toString();
		// 调用接口创建菜单
		JSONObject jsonObject = WeixinHttpClientUtils.httpRequest(requestUrl, "GET", null);

		return jsonObject;
	}

	/**
	 * 创建自定义菜单
	 * 
	 * @param customMenu
	 *            菜单实例
	 * @param accessToken
	 *            有效的access_token
	 * @return 0表示成功，其他值表示失败
	 */
	public static boolean createMenu(Menu Menu, String accessToken) {
		boolean result = false;
		String menu_create_url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=ACCESS_TOKEN";
		// 拼装创建菜单的url
		String requestUrl = menu_create_url.replace("ACCESS_TOKEN", accessToken);
		// 将菜单对象转换成json字符串
		String outputStr = JSONObject.fromObject(Menu).toString();
		// 调用接口创建菜单
		JSONObject jsonObject = WeixinHttpClientUtils.httpRequest(requestUrl, "POST", outputStr);
		if (null != jsonObject) {
			if (0 != jsonObject.getInt("errcode")) {
				result =false;
				log.error("创建菜单失败 errcode:{} errmsg:{}", jsonObject.getInt("errcode"), jsonObject.getString("errmsg"));
			}else{
				result=true;
			}
		}
		return result;
	}

	/**
	 * 创建个性化菜单
	 * 
	 * @param customMenu
	 *            菜单实例
	 * @param accessToken
	 *            有效的access_token
	 * @return 0表示成功，其他值表示失败
	 */
	public static boolean createIndividuationMenu(CustomMenu customMenu, String accessToken) {
		boolean flag =true;
		String menu_create_url = "https://api.weixin.qq.com/cgi-bin/menu/addconditional?access_token=ACCESS_TOKEN";
		// 拼装创建菜单的url
		String requestUrl = menu_create_url.replace("ACCESS_TOKEN", accessToken);
		// 将菜单对象转换成json字符串
		String outputStr = JSONObject.fromObject(customMenu).toString();
		// String outputStr =
		// "{\"button\":[{\"name\":\"商城活动\",\"sub_button\":{\"list\":[{\"type\":\"view\",\"name\":\"动景商城\",\"url\":\"http://55936673.m.weimob.com/vshop/55936673/Index\"},{\"type\":\"view\",\"name\":\"小鹰头拼团\",\"url\":\"http://55936673.m.weimob.com/vshop/Goods/GoodsDetail3/185650\"}]}},{\"name\":\"动景企业\",\"sub_button\":{\"list\":[{\"type\":\"view\",\"name\":\"动景年历\",\"url\":\"http://wei.taagoo.cn/mobile/2017year/chunjie.php?city=beautifulChina\"},{\"type\":\"view\",\"name\":\"动景名片\",\"url\":\"http://data.taagoo.com/pano/20161200034811.html\"},{\"type\":\"view\",\"name\":\"动景案例\",\"url\":\"http://www.taagoo.com/com/case/sh_sshyl/tour.html?rQfMSFk1wx=1\"}]}},{\"name\":\"动景社区\",\"sub_button\":{\"list\":[{\"type\":\"view\",\"name\":\"我要上传\",\"url\":\"http://we.taagoo.com/user-panoramic/upload.html\"},{\"type\":\"view\",\"name\":\"到处逛逛\",\"url\":\"http://m.we.taagoo.com/?winzoom=1\"}]}}]}";
		// 调用接口创建菜单
		JSONObject jsonObject = WeixinHttpClientUtils.httpRequest(requestUrl, "POST", outputStr);
		if (null != jsonObject) {
			boolean containsKey = jsonObject.containsKey("menuid");
			if(containsKey){
				flag=true;
				int result = jsonObject.getInt("menuid");
				log.info("创建个性化菜单成功  menuid:{}",result);
			}
			boolean containsKeyerrcode = jsonObject.containsKey("errcode");
			if (containsKeyerrcode) {
				if (0 != jsonObject.getInt("errcode")) {
					int result = jsonObject.getInt("errcode");
					flag=false;
					log.info("创建个性化菜单失败  errcode:{}",result);
				}
			}
		}
		return flag;
	}
	
	/**
	 * @date 2016年12月21日下午8:36:17
	 * @param token
	 * @return String
	 * @Des:菜单查询接口
	 */
	public static String demandMenu(String accessToken){
		
		String menu_create_url = "https://api.weixin.qq.com/cgi-bin/menu/get?access_token=ACCESS_TOKEN";
		String requestUrl = menu_create_url.replace("ACCESS_TOKEN", accessToken);
		JSONObject jsonObject = WeixinHttpClientUtils.httpRequest(requestUrl,"GET", null);
		String menu ="";
		if (null != jsonObject) {
			try {
				System.out.println("jsonObject"+jsonObject.toString());
				boolean containsValue = jsonObject.containsKey("errcode");
				boolean containsValue2 = jsonObject.containsKey("menu");
				boolean containsValue3 = jsonObject.containsKey("conditionalmenu");
				System.out.println(containsValue+"|"+containsValue2);
				if(containsValue){
					return "menu no exist";
				}
				if(containsValue2){
					menu = jsonObject.getString("menu");
				}
				if(containsValue3){
					menu += jsonObject.getString("conditionalmenu");
				}
				
			} catch (JSONException e) {
				e.printStackTrace();
			}
		}
		return menu;
	}
	/**
	 * @date 2016年12月21日下午8:39:40
	 * @param token void
	 * @Des:删除所有菜单
	 */
	public static boolean deleteMenu(String accessToken){
		boolean flag=false;
		String menu_create_url = "https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=ACCESS_TOKEN";
		String requestUrl = menu_create_url.replace("ACCESS_TOKEN", accessToken);
		//String json ="{\"menuid\":\""+menuid+"\"}";
		JSONObject jsonObject = WeixinHttpClientUtils.httpRequest(requestUrl,"POST",null);
		System.err.println("deleteMenu|jsonObject:"+jsonObject.toString());
		if (null != jsonObject) {
			boolean containsKeyerrcode = jsonObject.containsKey("errcode");
			if (containsKeyerrcode) {
				int result = jsonObject.getInt("errcode");
				if (0 != jsonObject.getInt("errcode")) {
					flag=false;
					log.info("删除菜单失败  errcode:{}",result);
				}else{
					flag=true;
					log.info("删除菜单成功  errcode:{}",result);

				}
			}
		}
		return flag;
		
	}
	
	/**
	 * @date 2016年12月21日下午8:39:40
	 * @param token void
	 * @Des:删除个性化菜单
	 */
	public static boolean delconditionalMenu(String accessToken,String menuid){
		boolean flag=false;
		String menu_delconditional_url = "https://api.weixin.qq.com/cgi-bin/menu/delconditional?access_token=ACCESS_TOKEN";
		String requestUrl = menu_delconditional_url.replace("ACCESS_TOKEN", accessToken);
		String json ="{\"menuid\":\""+menuid+"\"}";
		log.info("======删除个性化菜单输入参数======token="+accessToken+"menuid="+menuid);
		JSONObject jsonObject = WeixinHttpClientUtils.httpRequest(requestUrl,"POST", json);
		log.info("jsonObject======删除个性化菜单输出结果======"+jsonObject);
		if (null != jsonObject) {
			boolean containsKeyerrcode = jsonObject.containsKey("errcode");
			if (containsKeyerrcode) {
				int result = jsonObject.getInt("errcode");
				if (0 != jsonObject.getInt("errcode")) {
					flag=false;
					log.info("删除个性化菜单失败  errcode:{}",result);
				}else{
					flag=true;
					log.info("删除个性化菜单成功  errcode:{}",result);

				}
			}
		}
		return flag;
		
	}
	
	
	
	/**
	 * @date 2016年12月21日下午3:26:46
	 * @Des:添加客服帐号
	 */
	public static boolean addCustomer(String accessToken, String kf_account,
			String nickname, String password) {
		int result = 0;
		String sendMessage="https://api.weixin.qq.com/customservice/kfaccount/update?access_token=ACCESS_TOKEN";
		String json="{\"kf_account\":\""+kf_account+"\",\"nickname\":\""+nickname+"\",\"password\":\""+password+"\"}";
		String requestUrl = sendMessage.replace("ACCESS_TOKEN", accessToken);
		JSONObject jsonObject = WeixinHttpClientUtils.httpRequest(requestUrl,"POST", json);
		if (null != jsonObject) {
			try {
				System.out.println("addCustomer|jsonObject.toString():"+jsonObject.toString());
				boolean containsKeyerrcode = jsonObject.containsKey("errcode");
				if (containsKeyerrcode) {
					if (0 != jsonObject.getInt("errcode")) {
						result = jsonObject.getInt("errcode");
						System.out.println("GroupUtil|addUserGroup|errcode:"+result);
					    return false;
					}else{
						return true;
					}
				}
			} catch (JSONException e) {
				e.printStackTrace();
			}
		}
		
		return true;
	}

	/**
	 * @date 2016年12月21日下午3:26:46
	 * @param token
	 * @param openid
	 * @param to_groupid void
	 * @Des:发送客服消息
	 */
	public static boolean sendMessage(String token,String openid,String text){
		int result = 0;
		String sendMessage="https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=ACCESS_TOKEN";
		String json="{\"touser\":\""+openid+"\",\"msgtype\":\"text\",\"text\":{\"content\":\""+text+"\"}}";
		String requestUrl = sendMessage.replace("ACCESS_TOKEN", token);
		JSONObject jsonObject = WeixinHttpClientUtils.httpRequest(requestUrl,"POST", json);
		log.info("jsonObject!!!!!!!!!!!!!发送客服消息!!!!!++++++++"+jsonObject);
		if (null != jsonObject) {
			try {
				System.out.println("sendMessage|jsonObject.toString():"+jsonObject.toString());
				log.info("sendMessage|jsonObject.toString():"+jsonObject.toString());
				boolean containsKeyerrcode = jsonObject.containsKey("errcode");
				if (containsKeyerrcode) {
					if (0 != jsonObject.getInt("errcode")) {
						result = jsonObject.getInt("errcode");
						System.out.println("GroupUtil|addUserGroup|errcode:"+result);
						log.info("GroupUtil|addUserGroup|errcode:"+result);
						return false;
					}else{
						log.info("GroupUtil|addUserGroup|errcode:"+result);
						return true;
					}
				}
			} catch (JSONException e) {
				e.printStackTrace();
			}
		}
		return true;
	
	}
	/**
	 * 获取公众号的自动回复规则
	 * 
	 */
	public static JSONObject getReply(String accessToken) {
		String menu_create_url = "https://api.weixin.qq.com/cgi-bin/get_current_autoreply_info?access_token=ACCESS_TOKEN";
		// 拼装创建菜单的url
		String requestUrl = menu_create_url.replace("ACCESS_TOKEN", accessToken);
		// 调用接口创建菜单
		JSONObject jsonObject = WeixinHttpClientUtils.httpRequest(requestUrl, "GET", null);

		return jsonObject;
	}

	/**
	 * 创建临时带参数二维码
	 * 
	 * @param accessToken
	 * @expireSeconds 该二维码有效时间，以秒为单位。 最大不超过2592000（即30天），此字段如果不填，则默认有效期为30秒。
	 * @param sceneId
	 *            场景Id
	 * @return
	 */
	public static TicketPojo createTemporaryQrCode(String accessToken, String expireSeconds, String sceneId) {
		String ticket = null;
		TicketPojo pojo = null;
		String requestUrl = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=TOKEN";
		requestUrl = requestUrl.replace("TOKEN", accessToken);
		// 需要提交的JSON数据
		String outputStr = "{\"expire_seconds\":%s,\"action_name\":\"QR_SCENE\",\"action_info\":{\"scene\":{\"scene_id\":%s}}}";
		String format = String.format(outputStr, expireSeconds, sceneId);
		System.out.println(format);
		// 创建临时带参数二维码
		JSONObject jsonObject = WeixinHttpClientUtils.httpRequest(requestUrl, WeixinHttpClientUtils.POST_METHOD,format);
		log.info("jsonObject!!!!!!!!!!!!创建临时带参数二维码!!!!!!++++++++"+jsonObject);
		if (null != jsonObject) {
			try {
				pojo = new TicketPojo();
				ticket = jsonObject.getString("ticket");
				pojo.setTicket(ticket);
				pojo.setExpireSeconds(jsonObject.getString("expire_seconds"));
				pojo.setUrl(jsonObject.getString("url"));
				log.info("创建临时带参二维码成功,ticket=" + ticket + ",expire_seconds=" + jsonObject.getString("expire_seconds")
						+ ",url=" + jsonObject.getString("url"));
			} catch (Exception e) {
				String errorMsg = jsonObject.getString("errmsg");
				log.error("创建临时带参二维码失败,错误码是=" + errorMsg);
			}
		}
		return pojo;
	}

	/**
	 * 创建永久二维码
	 * 
	 * @param accessToken
	 * @param sceneId
	 *            场景Id
	 * @param sceneStr
	 *            场景IdsceneStr
	 * @return
	 */
	// 数字ID用这个{"action_name": "QR_LIMIT_SCENE", "action_info": {"scene":
	// {"scene_id": 123}}}
	// 或者也可以使用以下POST数据创建字符串形式的二维码参数：
	// 字符ID用这个{"action_name": "QR_LIMIT_STR_SCENE", "action_info": {"scene":
	// {"scene_str": "hfrunffgha"}}}
	public static TicketPojo createPermanentORCode(String accessToken, String sceneStr) {
		TicketPojo pojo = null;
		String ticket = null;
		String requestUrl = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=TOKEN";
		requestUrl = requestUrl.replace("TOKEN", accessToken);
		String outputStr = "{\"action_name\": \"QR_LIMIT_STR_SCENE\", \"action_info\":{\"scene\": {\"scene_str\":%s}}}";
		JSONObject jsonObject = WeixinHttpClientUtils.httpRequest(requestUrl, WeixinHttpClientUtils.POST_METHOD,
				String.format(outputStr, sceneStr));
		log.info("jsonObject!!!!!!!!!!!!!!!!!!++++++++"+jsonObject);
		if (null != jsonObject) {
			try {
				pojo = new TicketPojo();
				ticket = jsonObject.getString("ticket");
				pojo.setTicket(ticket);
				pojo.setExpireSeconds(jsonObject.getString("expire_seconds"));
				pojo.setUrl(jsonObject.getString("url"));
				log.info("创建永久带参二维码成功,ticket=" + ticket);
			} catch (Exception e) {
				/*String errorMsg = jsonObject.getString("errmsg");
				log.error("创建永久带参二维码失败,错误信息是=" + errorMsg);*/
			}
		}
		return pojo;
	}

	// 用ticket获取二维码
	public static String chageQrCode(String ticket) {
		String requestUrl = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=TICKET";
		requestUrl = requestUrl.replace("TICKET", ticket);
	 // String string = HttpClientUtil.doGet(requestUrl);
		return requestUrl;
	}

	/**
	 * 长链接转短链接接口
	 * 
	 * @param accessToken
	 *
	 * @return
	 */
	public static String createShortUrl(String accessToken, String qrUrl) {

		String shortUrl = null;
		String requestUrl = "https://api.weixin.qq.com/cgi-bin/shorturl?access_token=ACCESS_TOKEN";
		requestUrl = requestUrl.replace("TOKEN", accessToken);
		// 需要提交的JSON数据
		String outputStr = "{\"action\":\"long2short\",\"long_url\":%s}";

		// 创建临时带参数二维码
		JSONObject jsonObject = WeixinHttpClientUtils.httpRequest(requestUrl, WeixinHttpClientUtils.POST_METHOD,
				String.format(outputStr, qrUrl));
		log.info("jsonObject!!!!!!!!!!!!!!!!!!++++++++"+jsonObject);
		if (null != jsonObject) {
			try {
				shortUrl = jsonObject.getString("short_url");
				log.info("长链接转短链接接口成功," + jsonObject.getString("short_url"));
			} catch (Exception e) {
				log.error("创建临时带参二维码失败,错误码是=" + jsonObject.getString("errcode"));
			}
		}
		return shortUrl;
	}

	/**
	 * 获得模板ID
	 * @param accessToken
	 * @return
	 */
	public static String getIndustry(String accessToken) {
		String	result="";
		String menu_create_url = "https://api.weixin.qq.com/cgi-bin/template/api_add_template?access_token=ACCESS_TOKEN";
		// 获得模板ID的url
		String requestUrl = menu_create_url.replace("ACCESS_TOKEN", accessToken);
		// 调用获得模板ID
		JSONObject jsonObject = WeixinHttpClientUtils.httpRequest(requestUrl, "GET", null);
		if (null != jsonObject) {
			boolean containsKeyerrcode = jsonObject.containsKey("errcode");
			if(containsKeyerrcode){
				if (0 != jsonObject.getInt("errcode")) {
					log.info("获得模板ID失败  errcode:{}",jsonObject.getInt("result"));
				}
				result = jsonObject.getString("template_id");
			    log.info("获得模板ID成功  template_id:{}",jsonObject.getString("template_id"));
			
			}
			
		}
		return result;
	}
	
	
	/**
	 * 发送模板消息
	 * @param accessToken
	 * @return
	 */
	public static boolean sendTemplateMessage(String accessToken,String params) {
		boolean flag=true;
		String menu_create_url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=ACCESS_TOKEN";
		// 发送模板消息的url
		String requestUrl = menu_create_url.replace("ACCESS_TOKEN", accessToken);
		// 调用获得模板ID
		JSONObject jsonObject = WeixinHttpClientUtils.httpRequest(requestUrl, "POST", params);
		log.info("jsonObject!!!!!!!!!!!!!!!!发送模板消息!!++++++++"+jsonObject);
		if (null != jsonObject) {
			boolean containsKeyerrcode = jsonObject.containsKey("errcode");
			if(containsKeyerrcode){
				if (0 != jsonObject.getInt("errcode")) {
					log.info("发送模板消息失败  errcode:{}",jsonObject.getInt("result"));
					flag=false;
				}else{
					flag=true;
					log.info("发送模板消息成功  msgid:{}",jsonObject.getString("msgid"));
				}
			}
		}
		return flag;
	}
	
	
	
	/**
	 * 微信验证回调
	 * 
	 * @param request
	 * @param response
	 * 
	 * 
	 *            <xml><ToUserName><![CDATA[gh_2a5540516edb]]></ToUserName>
	 *            <FromUserName><![CDATA[odwP2jt6aTBu_Dl1ypoUJ8pN9UOs]]>
	 *            </FromUserName> <CreateTime>1425633941</CreateTime>
	 *            <MsgType><![CDATA[event]]></MsgType>
	 *            <Event><![CDATA[SCAN]]></Event>
	 *            <EventKey><![CDATA[0]]></EventKey> <Ticket>
	 *            <![CDATA[gQGK8DoAAAAAAAAAASxodHRwOi8vd2VpeGluLnFxLmNvbS9xL2RIVlBsRVBsdEhITk9jQzRaMXV6AAIEgXL5VAMECAcAAA==]]>
	 *            </Ticket> </xml>
	 */
	/*
	 * @RequestMapping(value="/init",method={RequestMethod.GET,RequestMethod.
	 * POST} ) public void initt(@RequestBody(required=false) String
	 * body,HttpServletRequest request,HttpServletResponse response){
	 * 
	 * System.out.println(body.toString()); System.out.println(
	 * "================================微信URL回调测试========================="); //
	 * saxReader saxReader = new SAXReader(); Document document; try { try {
	 * document = saxReader.read(new
	 * ByteArrayInputStream(body.toString().getBytes("UTF-8"))); Element rootElt
	 * = document.getRootElement();
	 * System.out.println("FromUserName==="+rootElt.elementText("FromUserName"))
	 * ; } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch
	 * block e.printStackTrace(); }
	 * 
	 * } catch (DocumentException e) { // TODO Auto-generated catch block
	 * e.printStackTrace(); } }
	 */

	/*
	 * 微信回调验证
	 * 
	 * String signature = request.getParameter("signature"); String timestamp =
	 * request.getParameter("timestamp"); String nonce =
	 * request.getParameter("nonce"); String echostr =
	 * request.getParameter("echostr");
	 * 
	 * String token = "dmx";
	 * 
	 * PrintWriter out; try { out = response.getWriter(); out.println(echostr);
	 * out.close(); response.flushBuffer(); } catch (IOException e) { // TODO
	 * Auto-generated catch block e.printStackTrace(); }
	 */

}